package com.example.dllo.baidumusic.main;
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         佛祖保佑       永无BUG
*/

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.dllo.baidumusic.R;
import com.example.dllo.baidumusic.nettool.BaseActivity;
import com.example.dllo.baidumusic.nettool.MyUser;

import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

/**
 * Created by dllo on 16/8/30.
 */
public class MeLoghActivity  extends BaseActivity {
    private Button btn;
    private TextView zhuceTv;
    private EditText username;
    private EditText password;
    @Override
    protected int setLayout() {

        return R.layout.activity_melogh;
    }

    @Override
    protected void initView() {
        btn = bindView(R.id.btn_denglu);
        zhuceTv = bindView(R.id.activity_melogh_zhuce);
        username = bindView(R.id.edit_username);
        password = bindView(R.id.edit_password);
        btn.setOnClickListener(this);
        zhuceTv.setOnClickListener(this);

    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_denglu:
                final MyUser myUser = new MyUser();
                myUser.setUsername(username.getText().toString());
                myUser.setPassword(password.getText().toString());
                myUser.login(new SaveListener<BmobUser>() {
                    @Override
                    public void done(BmobUser bmobUser, BmobException e) {
                        if (e == null){
                            Intent intent = new Intent(getApplication(),UserLogihActivity.class);
//                            setResult(RESULT_OK,intent);
                            startActivity(intent);
                            finish();
                            Toast.makeText(MeLoghActivity.this, "登陆成功", Toast.LENGTH_SHORT).show();
                        }else {
                            Toast.makeText(MeLoghActivity.this, "用户名/密码错误 请重新输入", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
                break;
            case R.id.activity_melogh_zhuce:
                Intent intent = new Intent(this,RegisterActivity.class);
                startActivity(intent);
                break;
        }

    }
}
